import React, {useState} from "react";
import {Card, Tabs, Button, Table, Tag, Select} from 'antd';
import {PageHeaderWrapper} from "@ant-design/pro-layout";
import styles from './index.less'

const {TabPane} = Tabs;
const {Option} = Select;

const ToolBtn = () => {
  return (
    <div className={styles.toolBtn}>
      <Button type="primary">发布商品</Button>
      <Button>批量删除</Button>
      <Button>上架</Button>
      <Button>下架</Button>
      <Button>推荐</Button>
      <Button>商品标签</Button>
      <Select defaultValue="lucy" style={{width: 120}} onChange={() => {

      }}>
        <Option value="jack">Jack</Option>
        <Option value="lucy">Lucy</Option>
      </Select>
    </div>
  );
};

const columns = [
  {
    title: 'Name',
    dataIndex: 'name',
    key: 'name',
    render: (text: any) => <a>{text}</a>,
  },
  {
    title: 'Age',
    dataIndex: 'age',
    key: 'age',
  },
  {
    title: 'Address',
    dataIndex: 'address',
    key: 'address',
  },
  {
    title: 'Tags',
    key: 'tags',
    dataIndex: 'tags',
    render: (tags: any) => (
      <span>
        {tags.map((tag: any) => {
          let color = tag.length > 5 ? 'geekblue' : 'green';
          if (tag === 'loser') {
            color = 'volcano';
          }
          return (
            <Tag color={color} key={tag}>
              {tag.toUpperCase()}
            </Tag>
          );
        })}
      </span>
    ),
  },
  {
    title: 'Action',
    key: 'action',
    render: (text: any, record: any) => (
      <span>
        <a style={{marginRight: 16}}>Invite {record.name}</a>
        <a>Delete</a>
      </span>
    ),
  },
];

const data = [
  {
    key: '1',
    name: 'John Brown',
    age: 32,
    address: 'New York No. 1 Lake Park',
    tags: ['nice', 'developer'],
  },
  {
    key: '2',
    name: 'Jim Green',
    age: 42,
    address: 'London No. 1 Lake Park',
    tags: ['loser'],
  },
  {
    key: '3',
    name: 'Joe Black',
    age: 32,
    address: 'Sidney No. 1 Lake Park',
    tags: ['cool', 'teacher'],
  },
];

const statusList = [
  {
    title: "出售中",
    key: "1"
  },
  {
    title: "已下架",
    key: "2"
  },
  {
    title: "库存预警",
    key: "3"
  },
  {
    title: "回收站",
    key: "4"
  },
];

export default () => {
  const [key, setKey] = useState("1");
  const [selectedKeys, setSelectedKeys] = useState([]);




  const rowSelection = {
    selectedRowKeys: selectedKeys,
    onChange: (selectedRowKeys: any) => {
      setSelectedKeys(selectedRowKeys)
    },
  };

  const TableList = () => {
    return (
      <Table columns={columns} dataSource={data} rowSelection={rowSelection}/>
    )
  };

  return (
    <PageHeaderWrapper title={false}>
      <Card bordered={false}>
        <Tabs defaultActiveKey="1" onChange={(activeKey) => {
          setKey(activeKey)
        }}>
          {
            statusList.map((item) =>
              <TabPane tab={item.title} key={item.key} style={{outline: "none"}}>
                {
                  key === item.key &&
                  <div>
                      <ToolBtn/>
                      <TableList/>
                  </div>
                }
              </TabPane>
            )
          }
        </Tabs>
      </Card>
    </PageHeaderWrapper>
  )
}
